using System;
using System.Collections.Generic;
using System.IO;
using Common;
using Common.Enum;
using Common.NotifyEvent;

namespace SSettings
{
	[Serializable]
	public class ExperimentSetting : NotifyPropertyChanged
	{
		private bool _AMPCurveDisplayThreshold = true;

		private bool _StandardCurverDisplayAll;

		private ESizeMode _CurverWidth = ESizeMode.Middle;

		private bool _HighLight = true;

		private EWellSelectMode _WellSelectMode;

		private bool _PressCtlCanSelectWell = true;

		private EChannelSelectMode _ChannelSelectMode = EChannelSelectMode.MultiClickCtl;

		private bool _UseSubset;

		private EAMPAlgorithm _AMPAlgorithm;

		private ESampleSortMode _SampleSortMode;

		private EDataRowSelectMode _DataRowSelectMode;

		private ERowSpaceMode _RowSpaceMode = ERowSpaceMode.Sample;

		private bool _ParamterVisible = true;

		private bool _WellPlateVisible = true;

		private bool _ShowCurveToolTips = true;

		private ECurveMaxYMode _CurveMaxYMode;

		private ESizeMode _TableSizeMode;

		private bool _UseScientific = true;

		private bool _ShowPeak;

		private EWellDisplayMode _WellDisplayMode;

		private bool _DisplayBackgroud;

		private int _OpenHotlidDelayTime = 5;

		public static string InternalCustomExportName = Utility.GetApplicationPath() + "customexport.exe";

		private bool _CustomExport;

		private string _CustomExportName;

		private ColorSettings _ColorSettings = new ColorSettings();

		private string _FixExperimentPath;

		private bool _MeltPeekInvertData;

		public bool AMPCurveDisplayThreshold
		{
			get
			{
				return _AMPCurveDisplayThreshold;
			}
			set
			{
				if (_AMPCurveDisplayThreshold != value)
				{
					_AMPCurveDisplayThreshold = value;
					OnPropertyChanged("AMPCurveDisplayThreshold");
				}
			}
		}

		public bool StandardCurverDisplayAll
		{
			get
			{
				return _StandardCurverDisplayAll;
			}
			set
			{
				if (_StandardCurverDisplayAll != value)
				{
					_StandardCurverDisplayAll = value;
					OnPropertyChanged("StandardCurverDisplayAll");
				}
			}
		}

		public ESizeMode CurverWidth
		{
			get
			{
				return _CurverWidth;
			}
			set
			{
				if (_CurverWidth != value)
				{
					_CurverWidth = value;
					OnPropertyChanged("CurverWidth");
				}
			}
		}

		public bool HighLight
		{
			get
			{
				return _HighLight;
			}
			set
			{
				if (_HighLight != value)
				{
					_HighLight = value;
					OnPropertyChanged("HighLight");
				}
			}
		}

		public EWellSelectMode WellSelectMode
		{
			get
			{
				return _WellSelectMode;
			}
			set
			{
				if (_WellSelectMode != value)
				{
					_WellSelectMode = value;
					OnPropertyChanged("WellSelectMode");
				}
			}
		}

		public bool PressCtlCanSelectWell
		{
			get
			{
				return _PressCtlCanSelectWell;
			}
			set
			{
				if (_PressCtlCanSelectWell != value)
				{
					_PressCtlCanSelectWell = value;
					OnPropertyChanged("PressCtlCanSelectWell");
				}
			}
		}

		public EChannelSelectMode ChannelSelectMode
		{
			get
			{
				return _ChannelSelectMode;
			}
			set
			{
				if (_ChannelSelectMode != value)
				{
					_ChannelSelectMode = value;
					OnPropertyChanged("ChannelSelectMode");
				}
			}
		}

		public bool UseSubset
		{
			get
			{
				if (ConfigReader.GetInstance().GetSubsetConfigFromIni() == 0)
				{
					return false;
				}
				return _UseSubset;
			}
			set
			{
				if (_UseSubset != value)
				{
					_UseSubset = value;
					OnPropertyChanged("UseSubset");
				}
			}
		}

		public EAMPAlgorithm AMPAlgorithm
		{
			get
			{
				return _AMPAlgorithm;
			}
			set
			{
				if (_AMPAlgorithm != value)
				{
					_AMPAlgorithm = value;
					OnPropertyChanged("AMPAlgorithm");
				}
			}
		}

		public ESampleSortMode SampleSortMode
		{
			get
			{
				return _SampleSortMode;
			}
			set
			{
				if (_SampleSortMode != value)
				{
					_SampleSortMode = value;
					OnPropertyChanged("SampleSortMode");
				}
			}
		}

		public EDataRowSelectMode DataRowSelectMode
		{
			get
			{
				return _DataRowSelectMode;
			}
			set
			{
				if (_DataRowSelectMode != value)
				{
					_DataRowSelectMode = value;
					OnPropertyChanged("DataRowSelectMode");
				}
			}
		}

		public ERowSpaceMode RowSpaceMode
		{
			get
			{
				return _RowSpaceMode;
			}
			set
			{
				if (_RowSpaceMode != value)
				{
					_RowSpaceMode = value;
					OnPropertyChanged("RowSpaceMode");
				}
			}
		}

		public bool ParamterVisible
		{
			get
			{
				return _ParamterVisible;
			}
			set
			{
				if (_ParamterVisible != value)
				{
					_ParamterVisible = value;
					OnPropertyChanged("ParamterVisible");
				}
			}
		}

		public bool WellPlateVisible
		{
			get
			{
				return _WellPlateVisible;
			}
			set
			{
				if (_WellPlateVisible != value)
				{
					_WellPlateVisible = value;
					OnPropertyChanged("WellPlateVisible");
				}
			}
		}

		public bool ShowCurveToolTips
		{
			get
			{
				return _ShowCurveToolTips;
			}
			set
			{
				if (_ShowCurveToolTips != value)
				{
					_ShowCurveToolTips = value;
					OnPropertyChanged("ShowCurveToolTips");
				}
			}
		}

		public ECurveMaxYMode CurveMaxYMode
		{
			get
			{
				return _CurveMaxYMode;
			}
			set
			{
				if (_CurveMaxYMode != value)
				{
					_CurveMaxYMode = value;
					OnPropertyChanged("CurveMaxYMode");
				}
			}
		}

		public ESizeMode TableSizeMode
		{
			get
			{
				return _TableSizeMode;
			}
			set
			{
				if (_TableSizeMode != value)
				{
					_TableSizeMode = value;
					OnPropertyChanged("TableSizeMode");
				}
			}
		}

		public bool UseScientific
		{
			get
			{
				return _UseScientific;
			}
			set
			{
				if (_UseScientific != value)
				{
					_UseScientific = value;
					OnPropertyChanged("UseScientific");
				}
			}
		}

		public bool ShowPeak
		{
			get
			{
				return _ShowPeak;
			}
			set
			{
				if (_ShowPeak != value)
				{
					_ShowPeak = value;
					OnPropertyChanged("ShowPeak");
				}
			}
		}

		public EWellDisplayMode WellDisplayMode
		{
			get
			{
				return _WellDisplayMode;
			}
			set
			{
				if (_WellDisplayMode != value)
				{
					_WellDisplayMode = value;
					OnPropertyChanged("WellDisplayMode");
				}
			}
		}

		public bool DisplayBackgroud
		{
			get
			{
				return _DisplayBackgroud;
			}
			set
			{
				if (_DisplayBackgroud != value)
				{
					_DisplayBackgroud = value;
					OnPropertyChanged("DisplayBackgroud");
				}
			}
		}

		public int OpenHotlidDelayTime
		{
			get
			{
				return _OpenHotlidDelayTime;
			}
			set
			{
				if (_OpenHotlidDelayTime != value)
				{
					_OpenHotlidDelayTime = value;
					OnPropertyChanged("OpenHotlidDelayTime");
				}
			}
		}

		public bool CustomExport
		{
			get
			{
				return _CustomExport;
			}
			set
			{
				if (_CustomExport != value)
				{
					_CustomExport = value;
					OnPropertyChanged("CustomExport");
				}
			}
		}

		public string CustomExportName
		{
			get
			{
				return _CustomExportName;
			}
			set
			{
				if (!(_CustomExportName == value))
				{
					_CustomExportName = value;
					OnPropertyChanged("CustomExportName");
				}
			}
		}

		public ColorSettings ColorSettings
		{
			get
			{
				return _ColorSettings;
			}
			set
			{
				if (_ColorSettings != value)
				{
					_ColorSettings = value;
					OnPropertyChanged("ColorSettings");
				}
			}
		}

		public string FixExperimentPath
		{
			get
			{
				if (string.IsNullOrEmpty(_FixExperimentPath))
				{
					return Utility.GetExperimentPath();
				}
				return _FixExperimentPath;
			}
			set
			{
				if (!(_FixExperimentPath == value))
				{
					_FixExperimentPath = value;
					OnPropertyChanged("FixExperimentPath");
				}
			}
		}

		public bool MeltPeekInvertData
		{
			get
			{
				return _MeltPeekInvertData;
			}
			set
			{
				if (_MeltPeekInvertData != value)
				{
					_MeltPeekInvertData = value;
					OnPropertyChanged("MeltPeekInvertData");
				}
			}
		}

		public ExperimentSetting()
		{
			ReSet();
		}

		public ExperimentSetting Clone()
		{
			ExperimentSetting experimentSetting = new ExperimentSetting();
			StreamEx streamEx = new StreamEx();
			SaveToStream(streamEx);
			streamEx.Seek(0L, SeekOrigin.Begin);
			experimentSetting.ReadFromStream(streamEx);
			streamEx.Close();
			return experimentSetting;
		}

		public void Copy(ExperimentSetting set)
		{
			StreamEx streamEx = new StreamEx();
			set.SaveToStream(streamEx);
			streamEx.Seek(0L, SeekOrigin.Begin);
			ReadFromStream(streamEx);
			streamEx.Close();
		}

		public void SaveToStream(StreamEx stream)
		{
			stream.Write(PropertyKey.Key_ExperimentSetting);
			List<PropertyKey> list = new List<PropertyKey>();
			List<byte[]> list2 = new List<byte[]>();
			list.Add(PropertyKey.Key_CustomImportName);
			list2.Add(BytesConverter.GetBytes(AMPCurveDisplayThreshold));
			list.Add(PropertyKey.Key_AutoSaveOption);
			list2.Add(BytesConverter.GetBytes(StandardCurverDisplayAll));
			list.Add(PropertyKey.Key_CurverWidth);
			list2.Add(BytesConverter.GetBytes((int)CurverWidth));
			list.Add(PropertyKey.Key_HighLight);
			list2.Add(BytesConverter.GetBytes(HighLight));
			list.Add(PropertyKey.Key_WellSelectMode);
			list2.Add(BytesConverter.GetBytes((int)WellSelectMode));
			list.Add(PropertyKey.Key_PressCtlCanSelectWell);
			list2.Add(BytesConverter.GetBytes(PressCtlCanSelectWell));
			list.Add(PropertyKey.Key_ChannelSelectMode);
			list2.Add(BytesConverter.GetBytes((int)ChannelSelectMode));
			list.Add(PropertyKey.Key_UseSubset);
			list2.Add(BytesConverter.GetBytes(UseSubset));
			list.Add(PropertyKey.Key_AMPAlgorithm);
			list2.Add(BytesConverter.GetBytes((int)AMPAlgorithm));
			list.Add(PropertyKey.Key_Use);
			list2.Add(BytesConverter.GetBytes((int)SampleSortMode));
			list.Add(PropertyKey.Key_WellNo);
			list2.Add(BytesConverter.GetBytes((int)DataRowSelectMode));
			list.Add(PropertyKey.Key_RowSpaceMode);
			list2.Add(BytesConverter.GetBytes((int)RowSpaceMode));
			list.Add(PropertyKey.Key_CurveParameters);
			list2.Add(BytesConverter.GetBytes(ParamterVisible));
			list.Add(PropertyKey.Key_ShowCurveToolTips);
			list2.Add(BytesConverter.GetBytes(ShowCurveToolTips));
			list.Add(PropertyKey.Key_FileExt);
			list2.Add(BytesConverter.GetBytes((int)CurveMaxYMode));
			list.Add(PropertyKey.Key_TableSizeMode);
			list2.Add(BytesConverter.GetBytes((int)TableSizeMode));
			list.Add(PropertyKey.Key_UseScientific);
			list2.Add(BytesConverter.GetBytes(UseScientific));
			list.Add(PropertyKey.Key_ShowPeak);
			list2.Add(BytesConverter.GetBytes(ShowPeak));
			list.Add(PropertyKey.Key_WellDisplayMode);
			list2.Add(BytesConverter.GetBytes((int)WellDisplayMode));
			list.Add(PropertyKey.Key_DisplayBackgroud);
			list2.Add(BytesConverter.GetBytes(DisplayBackgroud));
			list.Add(PropertyKey.Key_OpenHotlidDelayTime);
			list2.Add(BytesConverter.GetBytes(OpenHotlidDelayTime));
			list.Add(PropertyKey.Key_CustomExport);
			list2.Add(BytesConverter.GetBytes(CustomExport));
			if (!string.IsNullOrEmpty(_FixExperimentPath))
			{
				list.Add(PropertyKey.Key_FixExperimentPath);
				list2.Add(BytesConverter.GetBytes(_FixExperimentPath));
			}
			if (!string.IsNullOrEmpty(CustomExportName))
			{
				list.Add(PropertyKey.Key_CustomExportName);
				list2.Add(BytesConverter.GetBytes(CustomExportName));
			}
			list.Add(PropertyKey.Key_MeltPeekInvertData);
			list2.Add(BytesConverter.GetBytes(MeltPeekInvertData));
			list.Add(PropertyKey.Key_ColorSettings);
			StreamEx streamEx = new StreamEx();
			ColorSettings.SaveToStream(streamEx);
			streamEx.Seek(0L, SeekOrigin.Begin);
			list2.Add(streamEx.ToArray());
			streamEx.Close();
			stream.Write(PropertyKey.Key_Index);
			stream.WriteIndex(list, list2);
			stream.Flush();
		}

		public bool ReadFromStream(StreamEx stream)
		{
			PropertyKey propertyKey = stream.ReadKey();
			if (propertyKey != PropertyKey.Key_ExperimentSetting)
			{
				stream.Seek(-4L, SeekOrigin.Current);
				return false;
			}
			propertyKey = stream.ReadKey();
			if (propertyKey == PropertyKey.Key_Index)
			{
				List<PropertyKey> keys;
				List<byte[]> dates;
				stream.ReadIndex(out keys, out dates);
				bool flag = true;
				for (int i = 0; i < keys.Count; i++)
				{
					if (!flag)
					{
						return false;
					}
					switch (keys[i])
					{
					case PropertyKey.Key_CustomImportName:
						AMPCurveDisplayThreshold = BytesConverter.BytesToBool(dates[i]);
						break;
					case PropertyKey.Key_AutoSaveOption:
						StandardCurverDisplayAll = BytesConverter.BytesToBool(dates[i]);
						break;
					case PropertyKey.Key_CurverWidth:
						CurverWidth = (ESizeMode)BytesConverter.BytesToInt(dates[i]);
						break;
					case PropertyKey.Key_HighLight:
						HighLight = BytesConverter.BytesToBool(dates[i]);
						break;
					case PropertyKey.Key_WellSelectMode:
						WellSelectMode = (EWellSelectMode)BytesConverter.BytesToInt(dates[i]);
						break;
					case PropertyKey.Key_PressCtlCanSelectWell:
						PressCtlCanSelectWell = BytesConverter.BytesToBool(dates[i]);
						break;
					case PropertyKey.Key_ChannelSelectMode:
						ChannelSelectMode = (EChannelSelectMode)BytesConverter.BytesToInt(dates[i]);
						break;
					case PropertyKey.Key_UseSubset:
						UseSubset = BytesConverter.BytesToBool(dates[i]);
						break;
					case PropertyKey.Key_AMPAlgorithm:
						AMPAlgorithm = (EAMPAlgorithm)BytesConverter.BytesToInt(dates[i]);
						break;
					case PropertyKey.Key_Use:
						SampleSortMode = (ESampleSortMode)BytesConverter.BytesToInt(dates[i]);
						break;
					case PropertyKey.Key_WellNo:
						DataRowSelectMode = (EDataRowSelectMode)BytesConverter.BytesToInt(dates[i]);
						break;
					case PropertyKey.Key_RowSpaceMode:
						RowSpaceMode = (ERowSpaceMode)BytesConverter.BytesToInt(dates[i]);
						break;
					case PropertyKey.Key_CurveParameters:
						ParamterVisible = BytesConverter.BytesToBool(dates[i]);
						break;
					case PropertyKey.Key_ShowCurveToolTips:
						ShowCurveToolTips = BytesConverter.BytesToBool(dates[i]);
						break;
					case PropertyKey.Key_FileExt:
						CurveMaxYMode = (ECurveMaxYMode)BytesConverter.BytesToInt(dates[i]);
						break;
					case PropertyKey.Key_TableSizeMode:
						TableSizeMode = (ESizeMode)BytesConverter.BytesToInt(dates[i]);
						break;
					case PropertyKey.Key_UseScientific:
						UseScientific = BytesConverter.BytesToBool(dates[i]);
						break;
					case PropertyKey.Key_ShowPeak:
						ShowPeak = BytesConverter.BytesToBool(dates[i]);
						break;
					case PropertyKey.Key_WellDisplayMode:
						WellDisplayMode = (EWellDisplayMode)BytesConverter.BytesToInt(dates[i]);
						break;
					case PropertyKey.Key_DisplayBackgroud:
						DisplayBackgroud = BytesConverter.BytesToBool(dates[i]);
						break;
					case PropertyKey.Key_OpenHotlidDelayTime:
						OpenHotlidDelayTime = BytesConverter.BytesToInt(dates[i]);
						break;
					case PropertyKey.Key_CustomExport:
						CustomExport = BytesConverter.BytesToBool(dates[i]);
						break;
					case PropertyKey.Key_CustomExportName:
						CustomExportName = BytesConverter.BytesToString(dates[i]);
						break;
					case PropertyKey.Key_ColorSettings:
					{
						StreamEx streamEx = new StreamEx();
						streamEx.Write(dates[i]);
						streamEx.Seek(0L, SeekOrigin.Begin);
						ColorSettings.ReadFromStream(streamEx);
						streamEx.Close();
						break;
					}
					case PropertyKey.Key_FixExperimentPath:
						FixExperimentPath = BytesConverter.BytesToString(dates[i]);
						break;
					case PropertyKey.Key_MeltPeekInvertData:
						MeltPeekInvertData = BytesConverter.BytesToBool(dates[i]);
						break;
					}
				}
				return true;
			}
			stream.Seek(-4L, SeekOrigin.Current);
			while (true)
			{
				switch (stream.ReadKey())
				{
				case PropertyKey.Key_Type:
					stream.ReadInt();
					break;
				case PropertyKey.Key_CustomImportName:
					AMPCurveDisplayThreshold = stream.ReadBool();
					break;
				case PropertyKey.Key_AutoSaveOption:
					StandardCurverDisplayAll = stream.ReadBool();
					break;
				case PropertyKey.Key_CurverWidth:
				{
					ESizeMode eSizeMode = (ESizeMode)stream.ReadInt();
					if (eSizeMode != ESizeMode.Large && eSizeMode != ESizeMode.Middle && eSizeMode != 0)
					{
						eSizeMode = ESizeMode.Middle;
					}
					CurverWidth = eSizeMode;
					break;
				}
				case PropertyKey.Key_HighLight:
					HighLight = stream.ReadBool();
					break;
				case PropertyKey.Key_WellSelectMode:
					WellSelectMode = (EWellSelectMode)stream.ReadInt();
					break;
				case PropertyKey.Key_PressCtlCanSelectWell:
					PressCtlCanSelectWell = stream.ReadBool();
					break;
				case PropertyKey.Key_ChannelSelectMode:
					ChannelSelectMode = (EChannelSelectMode)stream.ReadInt();
					break;
				case PropertyKey.Key_UseSubset:
					UseSubset = stream.ReadBool();
					break;
				case PropertyKey.Key_AMPAlgorithm:
					AMPAlgorithm = (EAMPAlgorithm)stream.ReadInt();
					break;
				case PropertyKey.Key_Use:
					SampleSortMode = (ESampleSortMode)stream.ReadInt();
					break;
				case PropertyKey.Key_WellNo:
					DataRowSelectMode = (EDataRowSelectMode)stream.ReadInt();
					break;
				case PropertyKey.Key_RowSpaceMode:
					RowSpaceMode = (ERowSpaceMode)stream.ReadInt();
					break;
				case PropertyKey.Key_CurveParameters:
					ParamterVisible = stream.ReadBool();
					break;
				case PropertyKey.Key_CurveParameter:
					stream.ReadBool();
					WellPlateVisible = true;
					break;
				case PropertyKey.Key_ShowCurveToolTips:
					ShowCurveToolTips = stream.ReadBool();
					break;
				case PropertyKey.Key_FileExt:
					CurveMaxYMode = (ECurveMaxYMode)stream.ReadInt();
					break;
				case PropertyKey.Key_TableSizeMode:
				{
					ESizeMode eSizeMode = (ESizeMode)stream.ReadInt();
					if (eSizeMode != ESizeMode.Large && eSizeMode != ESizeMode.Middle && eSizeMode != 0)
					{
						eSizeMode = ESizeMode.Small;
					}
					TableSizeMode = eSizeMode;
					break;
				}
				case PropertyKey.Key_UseScientific:
					UseScientific = stream.ReadBool();
					break;
				case PropertyKey.Key_ShowPeak:
					ShowPeak = stream.ReadBool();
					break;
				case PropertyKey.Key_WellDisplayMode:
					WellDisplayMode = (EWellDisplayMode)stream.ReadInt();
					break;
				case PropertyKey.Key_DisplayBackgroud:
					DisplayBackgroud = stream.ReadBool();
					break;
				case PropertyKey.Key_OpenHotlidDelayTime:
					OpenHotlidDelayTime = stream.ReadInt();
					break;
				default:
					stream.Seek(-4L, SeekOrigin.Current);
					return true;
				}
			}
		}

		public void ReSet()
		{
			AMPCurveDisplayThreshold = true;
			StandardCurverDisplayAll = false;
			CurverWidth = ESizeMode.Middle;
			HighLight = true;
			WellSelectMode = EWellSelectMode.Sample;
			PressCtlCanSelectWell = true;
			ChannelSelectMode = EChannelSelectMode.MultiClickCtl;
			UseSubset = false;
			AMPAlgorithm = EAMPAlgorithm.Default;
			SampleSortMode = ESampleSortMode.Column;
			DataRowSelectMode = EDataRowSelectMode.Target;
			RowSpaceMode = ERowSpaceMode.Null;
			ParamterVisible = true;
			WellPlateVisible = true;
			ShowCurveToolTips = true;
			CurveMaxYMode = ECurveMaxYMode.AllWells;
			TableSizeMode = ESizeMode.Small;
			UseScientific = true;
			ShowPeak = false;
			WellDisplayMode = EWellDisplayMode.ProjectName;
			DisplayBackgroud = false;
			OpenHotlidDelayTime = 5;
			FixExperimentPath = string.Empty;
		}
	}
}
